#ifndef __BSP_AHT21_H
#define __BSP_AHT21_H

#include "stdint.h"
#include "stdio.h"

/*上层提供的IIC接口 */
typedef struct
{
    void (*pfIICStart)(iic_bus_t *bus);
    void (*pfIICStop)(iic_bus_t *bus);
    unsigned char (*pfIICWaitAck)(iic_bus_t *bus);
    void (*pfIICSendAck)(iic_bus_t *bus);
    void (*pfIICSendNotAck)(iic_bus_t *bus);
    void (*pfIICSendByte)(iic_bus_t *bus, unsigned char cSendByte);
    unsigned char (*pfIICReceiveByte)(iic_bus_t *bus);
    void (*pfIICInit)(iic_bus_t *bus);

    // uint8_t (*pfIIC_Write_One_Byte)(iic_bus_t *bus, uint8_t daddr,uint8_t reg,uint8_t data);
    // uint8_t (*pfIIC_Write_Multi_Byte)(iic_bus_t *bus, uint8_t daddr,uint8_t reg,uint8_t length,uint8_t buff[]);
    // unsigned char (*pfIIC_Read_One_Byte)(iic_bus_t *bus, uint8_t daddr,uint8_t reg);
    // uint8_t (*pfIIC_Read_Multi_Byte)(iic_bus_t *bus, uint8_t daddr, uint8_t reg, uint8_t length, uint8_t buff[]);
} iic_driver_interface_t;

/*上层提供的时基接口 */
typedef struct
{
    uint32_t (*pfHAL_GetTick)();
} sys_timebase_t;

/*上层提供的关闭全局中断函数*/
typedef struct
{
    void (*pfdisable_irq)(void);
    void (*pfenable_irq)(void);
} sys_irq_manager_t;

/*聚合结构体 */
typedef struct
{   
    uint8_t                  ath21_id;
    iic_driver_interface_t*  iic_instance;
    sys_timebase_t*          sys_timebase;
    sys_irq_manager_t*       sys_irq_manager;

    //本层函数
    uint8_t (*pfaht21_init)(void);
    uint8_t (*pfaht21_read_tem)(uint8_t* temperature);
    uint8_t (*pfaht21_read_hum)(uint8_t* humidity);

    //构造函数
    uint8_t (*pfinit_str)( bsp_aht21_driver_t*       bsp_aht21_driver,
                           iic_driver_interface_t*   iic_driver_interface,
                           sys_timebase_t*           sys_timebase,
                           sys_irq_manager_t*        sys_irq_manager);

} bsp_aht21_driver_t;

static uint8_t aht21_init(void);
static uint8_t aht21_read_tem(uint8_t* temperature);
static uint8_t pfaht21_read_hum(uint8_t* humidity);
static uint8_t init_str ( bsp_aht21_driver_t*       bsp_aht21_driver,
                           iic_driver_interface_t*   iic_driver_interface,
                           sys_timebase_t*           sys_timebase,
                           sys_irq_manager_t*        sys_irq_manager);
#endif
